#include <iostream>
using namespace std;

struct TreeNode{
	char elem;
	TreeNode * left;
	TreeNode * right;
};

int getLength(char * s){
	int i = 0;
	for(;;){
		if(s[i] == '\0') break;
		i++;
	}
	return i;
}

TreeNode * buildTree(char * middle, int middle_left, int middle_right, char * post, int post_left, int post_right){
	if(middle_left > middle_right || post_left > post_right) return NULL;
	TreeNode * root = new TreeNode;
	if(middle_left == middle_right){
		root->elem = middle[middle_left];
		root->left = root->right = NULL;
		return root;
	}
	root->elem = post[post_right];
	int site;
	for(site = middle_left; site <= middle_right; site++)
		if(middle[site] == root->elem) break;
	int sonLength = site - middle_left;
	root->left = buildTree(middle, middle_left, site - 1, post, post_left, post_left + sonLength - 1);
	root->right = buildTree(middle, site + 1, middle_right, post, post_left + sonLength, post_right - 1);
	return root;
}

void preOrderTraverse(TreeNode * root){
	if(root){
		cout << root->elem;
		preOrderTraverse(root->left);
		preOrderTraverse(root->right);
	}
}

int main(){
	char * middle = new char[9];
	char * post = new char[9];

	cin >> middle;
	cin >> post;

	int middleLength = getLength(middle);
	int postLength = getLength(post);

	TreeNode * root = buildTree(middle,0,middleLength-1,post,0,postLength-1);
	preOrderTraverse(root);
	return 0;
}
